<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path;
%>
<html style="font-size: 66.5333px;">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<title>核销</title>
 <link href="${pageContext.request.contextPath}/css/system/h5_login.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-weui/1.2.0/css/jquery-weui.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-weui/1.2.0/css/jquery-weui.min.css" rel="stylesheet">
<style type="text/css">
	.int2{width:100%; height:50px;float:left}
	.couponCodeClass{width:80%;height:40px;float:left;    border: 1px solid #dddddd;
    padding-left: 40px;
    box-sizing: border-box;
    border-radius: 6px;}
	.search{width:60px;    border-radius: 6px;
    background-color: #1ab394;height: 38px;
    border: 0;
    color: white;}
    .margin-top{
       margin-top:10px;
    }
    
    #login {
    margin-top: 20px;
    width: 50%;
    height: 33px;
    border: 0;
    color: white;
    font-size: 18px;
    margin-bottom: 10px;
    border-radius: 6px;
    background-color: #1ab394;
}
</style>
</head>
<body>
	<div id="panel">
		<!--面板的主要内容-->
		<div class="panel-content">
			<div class="int2">
				 <input id="couponCode" class="couponCodeClass"
					type="text" placeholder="请输入优惠券码"><button class="search" id="search" type="button">查询</button></div>
			<!--配置信息-->
		</div>
		<div id="couponInfo" hidden="" class="couponInfoDiv" class="form-horizontal m-t text-center">
               <div class="margin-top">
                   <p id="couponName" class="col-sm-6 text-left"></p>
               </div>
               <div class="margin-top">
                   <p id="couponType" class="col-sm-6 text-left"></p>
               </div>
               <div class="margin-top">
                   <p id="couponCode" class="col-sm-6 text-left"></p>
               </div>
               <div class="margin-top">
                   <p id="limitPrice" class="col-sm-6 text-left"></p>
               </div>
               <div class="margin-top">
                   <p id="validityPeriod" class="col-sm-9 text-left"></p>
               </div>
                <div class="margin-top">
                   <p id="useTime" class="col-sm-6 text-left"></p>
               </div>
       </div>
       <div class="login2 couponInfoDiv" hidden="" id="verifyBtn">
			<button id="verifyBtn">核销</button>
	   </div>
		<!--面板的底部-->
	</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script type="text/javascript" src="<%=path%>/js/marketing/public.js"></script>
<script type="text/javascript" src="<%=path%>/js/dateUtils.js"></script>
<script type="text/javascript">
 var cid ;
 var path = "<%=path%>";
 var couponId ;
 $(function(){
	cid=getQueryString("cid"); 
 })
 $('#search').click(function(){	
	 $(".couponInfoDiv").hide();
	//获取验证编码
	  var coupon_code =$('#couponCode').val();
	  var params = {
		  "couponCode" : coupon_code,
		  "cid" : cid	  
	  };   	 
	  $.ajax({
		  type : "post",
		  url : path+"/coupon/ajaxGetCouponSendRecordByDto",
		  dataType : "json",
		  data : params,
		  async:false,
		  success : function(data){ 
			  $('.bm_con').html("");
			  var b = data.status;
			  var b2 = data.message;	
			  if(200 == b){   	
				 $('.couponInfoDiv').show();
				 var couponInfo= data.data;
				 couponId=couponInfo.couponId;
	   			 $("#couponName").html("券名:"+couponInfo.name);
	   			 $("#couponCode").html("券码:"+coupon_code);
	   			 //种类
	   			if(couponInfo.type==0){
	   				 $("#couponType").html("种类:代金券");
	   			 }else if(couponInfo.type==1){
	   				$("#couponType").html("种类:物品券");
	   			 }
	   			 
	   			 //满减
	   			 var limitPrice=couponInfo.limitPrice;
	   			 if(StringEmpty(limitPrice)&&limitPrice!=0){
	   				 $("#limitPrice").html("满减规则:满"+limitPrice/100+"使用");
	   			 }else {
	   				$("#limitPrice").html("满减规则:无");
	   			 }
	   			 //有效期
	   			 if(StringEmpty(couponInfo.validityPeriodType+"")&&couponInfo.validityPeriodType==0){
	   				 $('#validityPeriod').html("有效期:"+formatDateTimeYMD(couponInfo.startTime)+" 至 "+formatDateTimeYMD(couponInfo.endTime));
	   			 }else if(StringEmpty(couponInfo.validityPeriodType+"")&&couponInfo.validityPeriodType==1){
	   				 $('#validityPeriod').html("有效期:"+formatDateTimeYMD(couponInfo.createTime)+" 至 "+formatDateTimeYMD(couponInfo.expiryDate));
	   			 }else{
	   				 $('#validityPeriod').html("有效期:无");
	   			 }
	   			 
	   			 //适用时段
	   			 if(StringEmpty(couponInfo.useTimeType+"")&&couponInfo.useTimeType==0){
	   				$('#useTime').html("适用时段:无");
	   			 }else if(StringEmpty(couponInfo.useTimeType+"")&&couponInfo.useTimeType==1){
	   				$('#useTime').html("适用时段:"+couponInfo.periodTimeWeek+" "+couponInfo.periodTimeHour);
	   			 }else{
	   				 $('#useTime').html("适用时段:无");
	   			 }
	   			  
	   	       }else if ("601" == b) {  
	   	    	    alert("不存在该优惠券");
		       }else if(b == "602"){
		    	    alert("该优惠券已消费");
		       }else/* if(b == "3")*/{
		    	   alert("请输入优惠券码");
		       } 			  
		  }   		  
	   }); 
 }); 
 
 $('#verifyBtn').click(function(){
		var couponCode = $('#couponCode').val();
		var params = {
				"cid" : cid,
				"id" : couponId
		};			
		$.ajax({			
			type: "post",
			url : path+"/coupon/ajaxWriteoff",
			dataType : "json",
			data: params,
			async: false,
			success : function(data){		
				if(data.status == "200"){				
					alert("核销成功");
				}else if(data.status=="602"){
					alert("券码不存在");
				}else if(data.status=="603"){
                 alert("该优惠券已过期");
                }else if(data.status=="601"){
					alert("该优惠券已核销，请勿反复核销");
				}
			},
			error: function(data){
				alert("操作出错，请重试");
       	  	window.location.reload();
         }
		});
	 });

</script>


</html>
